package com.ruoyi.job.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliPayConfiguration {

    @Bean
    public AlipayConfig alipayConfig(){
//        AlipayConfig alipayConfig = new AlipayConfig();
//        alipayConfig.setServerUrl("https://openapi.alipaydev.com/gateway.do");
//        alipayConfig.setAppId("2021000122612714");
//        alipayConfig.setPrivateKey(privateKey);
//        alipayConfig.setFormat("json");
//        alipayConfig.setAlipayPublicKey(alipayPublicKey);
//        alipayConfig.setCharset("UTF8");
//        alipayConfig.setSignType("RSA2");

        AlipayConfig alipayConfig = new AlipayConfig();
        //支付宝测试环境服务器
        alipayConfig.setServerUrl("https://openapi.alipaydev.com/gateway.do");
        //支付宝应用id，在沙箱环境内获取
        alipayConfig.setAppId("2021000122612714");
        //引用私钥，建议使用《支付宝开放平台开发助手》生成，RSA2
        alipayConfig.setPrivateKey("MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCZ+jcSxc2S8L5MLFki+zBVMj1oJWaGXvubQmxtQCklvSFu5Kfs9x8EIN5S5XDlExzpYn8WyH2Prcg2VLAGSSy25d94bWlapEdwUIwLwKWPUd9ql58Y1jPMk55vsGM5RlZrHovTkdQBTuEmibD01h3Q3ngcTKdetytuhN/HZRrEE7kAwjvq23MHToOaL5iZ4T3/bhFy+TqnT5BZpP1qp/t/pF7rUE7VX5D0qhUw+d85MALcWhx6/DijAAgmn6hXSiIQujDucrIW1opKO8YwuItVJOzTAKZPc0Nn+1Tk63/eDG8Z69h2VDI3pnjeq5JpIPTBND3e3oKbDmeDtAoacg5JAgMBAAECggEAdcsNRrc7xSWW7v8eUbyIBSUiBQJXpIQVR3lRKWLkF5LQeN1D+ewzNh1O92u/Kf+tJn3La8qFA92WRLoUzzo7ks/YXXCWIFl8rVdxS6xc+39Ow2SquX1ksy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xhFLpEduWTaefJu4PYWExyz6HObbSD");

        //json
        alipayConfig.setFormat("json");
        //支付宝的公钥，不是咱自己的。沙箱应用处获取
        alipayConfig.setAlipayPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0R+Buh5cwTjb/WGFwTcpdCQUguAZ+zbQ8Jh84sV8RXVQqszN4MyjTln5mB6hNH29EiiKNmz0QB27Etrsj+FwK4bio99ey4hkzSIsO1SKcg4EInWxxiayZ/5GARsGnAGrgHhfY1GUKsITdz0VckLpaXOK5QvNmuJAZyp4i2OLRfYQuTa8YjDt0wkdFvMFT8lh1SlmWjyOAekVFGbSJv3GxbhqekJaWNPtYP9rvWpnKhhmci6QNnkQdvBjDrwHpTu+W4lJQe/gj6SI7h5J3jeR4KfTKmGWg6yu6rMk05MxFeCrndD9nNsAnmrHs2IaLuKAk5X1GCE47AgbRd+mW/e+IQIDAQAB");

        //UTF-8
        alipayConfig.setCharset("UTF8");
        //RSA2
        alipayConfig.setSignType("RSA2");
        return alipayConfig;
    }

    @Bean
    public AlipayClient alipayClient(AlipayConfig config){
        try {
            return  new DefaultAlipayClient(config);
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
    }

}
